﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace Seminarska
{
    class DB
    {
        private static string connectionString = Seminarska.Properties.Settings.Default.Products;

        public static DataTable GetProducts()
        {
            SqlConnection con = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand("SELECT * FROM Produkti", con);
            cmd.CommandType = CommandType.Text;
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            adapter.Fill(ds, "products");
            return ds.Tables[0];
        }

        public static DataTable GetVraboteni()
        {
            SqlConnection con = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand("SELECT * FROM Vraboteni", con);
            cmd.CommandType = CommandType.Text;
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            adapter.Fill(ds, "vraboteni");
            return ds.Tables[0];
        }

      public static void dodadiProdukt(string kod, string ime, string proiz, double cena)
        {
          
            SqlConnection con = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;

           

            cmd.Parameters.AddWithValue("@kod", kod);
            cmd.Parameters.AddWithValue("@ime", ime);
            cmd.Parameters.AddWithValue("@proiz", proiz);
            cmd.Parameters.AddWithValue("@cena", cena);

            cmd.Parameters.AddWithValue("@slika", "non.jpg");

            cmd.CommandText = "INSERT INTO Produkti ( Kod, Imep, Proizvoditel, Cena, Slika )" +
                            "VALUES (@kod, @ime, @proiz, @cena, @slika)";

            try
            {
                con.Open();

                cmd.ExecuteNonQuery();
            }

            finally
            {
                con.Close();
            }
           
        }

      public static void dodadiVraboten(string maticen, string ime, string prezime, string mobilen, string adresa, string grad, string pozicija, double plata)
      {

          SqlConnection con = new SqlConnection(connectionString);
          SqlCommand cmd = new SqlCommand();
          cmd.Connection = con;



          cmd.Parameters.AddWithValue("@EMBG", maticen);
          cmd.Parameters.AddWithValue("@Imev", ime);
          cmd.Parameters.AddWithValue("@Prezv", prezime);
          cmd.Parameters.AddWithValue("@Mobilen", mobilen);
          cmd.Parameters.AddWithValue("@Adresa", adresa);
          cmd.Parameters.AddWithValue("@Grad", grad);
          cmd.Parameters.AddWithValue("@Pozicija", pozicija);
          cmd.Parameters.AddWithValue("@Plata", plata);

          cmd.CommandText = "INSERT INTO Vraboteni ( EMBG, Imev, Prezv, Mobilen, Adresa,Grad,Pozicija,Plata )" +
                          "VALUES ( @EMBG, @Imev, @Prezv, @Mobilen, @Adresa,@Grad,@Pozicija,@Plata)";

          try
          {
              con.Open();

              cmd.ExecuteNonQuery();
          }

          finally
          {
              con.Close();
          }

      }
    }
}
